;
(function () {

    $(function () {
        //入口函数
        $.idcode.setCode(); //加载生成验证码方法

        $("form").validate({
            rules: {
                u_phone: {
                    required: true
                },
                u_pwd: {
                    required: true
                },
            },
            messages: {
                u_phone: "用户名必填",
                u_pwd: "密码必填",

            },
            submitHandler() {

                var IsBy = $.idcode.validateCode();
                if (!IsBy) {
                    layer.msg("验证码错误")
                    return false;
                }
               
                $.ajax({
                    url:"./api/login",
                    type:"post",
                    data:$("form").serialize(),
                }).done((res)=>{
                    if(res.status==1){
                        
                        localStorage.setItem("users",JSON.stringify(res.data));
                        layer.confirm("登录成功!",{
                            btn:["确定","取消"]
                        },(index)=>{
                            layer.close(index);
                            location="./index.html";
                        },()=>{

                        })
                    }else{
                        layer.msg(res.msg)
                    }
                })
                return false;
            }
        })
        $("#hyz").on("click",function(){
            $.idcode.setCode();
        })
    })
})();